package com.cn.designpatterns.ex.concrete.observer.simple;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyi
 * @date 2018/12/24 17:28
 */
public abstract class Subject {

    private List<Observer> observers = new ArrayList<>();
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObserver();
    }

    public void attach(Observer observer){
        observers.add(observer);
    }
    public void notifyAllObserver(){
        for(Observer o : observers){
            o.update();
        }
    }
}
